/**
 * 注册路由
 * @param routes
 * @param mode
 * @returns
 */
function createRouter(routes, mode='history') {
    const matcherMap = new Map()
    for (let route of routes) {
        matcherMap.set(route.name, route)
    }

    // 添加路由
    function addRoutes(routes) {
        for (let route of routes) {
            matcherMap.set(route.name, route)
        }
    }

    // 删除路由
    function removeRoutes(routes) {
        for (let route of routes) {
            matcherMap.delete(route.name)
        }
    }

    // 获取路由
    function getRoutes() {
        return matcherMap
    }

    // 获取指定路由
    function getRoute(name) {
        return matcherMap.get(name)
    }

    return {
        addRoutes,
        removeRoutes,
        getRoutes,
        getRoute
    }
}
